<?php
namespace App\Http\Controllers\Admin;
use Illuminate\Http\Request;
class BankController extends \App\Http\Controllers\AdminController{
    //提现银行列表
    public function index() {
        $banks = \App\Models\Bank::orderBy('id', 'asc')->paginate();
        $assign = compact('banks');
        return view('admin.bank.index', $assign);
    }
    
    /**
     * 修改/删除提现银行
     * @param Request $request
     * @param type $id
     * @param type $status
     * @return type
     */
    public function edit(Request $request, $id, $status=false) {
        $bank = \App\Models\Bank::find($id);
        if (!$bank) {
            return \Illuminate\Support\Facades\Response::json([
                'status'    => 0,
                'info'      => '商品不存在'
            ]);
        }
        if ($status === '0') {
            $bank->delete();
            return \Illuminate\Support\Facades\Response::json([
                'status'    => 1,
                'info'      => '删除成功'
            ]);
        }
        if ($request->ajax()) {
            $bank->name = $request->input('name');
            $bank->save();
            return \Illuminate\Support\Facades\Response::json([
                'status'    => 1,
                'info'      => '修改成功'
            ]);
        }
        $assign = compact('bank');
        return view('admin.bank.edit', $assign);
    }
    /**
     * 添加新小区
     */
    public function add(Request $request) {
        if ($request->ajax()) {
            return \App\Models\Bank::addBank($request);
        }
        
        return view('admin.bank.add');
    }
}
